Fall back to open Positron notebooks in notebooks.getContext when none is the active editor pane#14842
Merged
Merged
Conversation
…nactive notebooks
positron.notebooks.getContext resolved the notebook only from the active editor pane, so assistant tools reported 'no notebook is open in the editor' whenever focus was in another editor (chat editor, split group, another tab) even though a Positron notebook was open. Fall back to the most recently active open Positron notebook, resolved through the editor service's MRU list against registered notebook instances.
The confirmed repro for #14762 (Data Explorer or plot editor takes the active pane while the notebook session stays foreground) shows assistant notebook mode is keyed on the foreground session. Resolve that notebook first so getContext agrees with the mode and the interpreter picker; keep the MRU editor fallback for cases where the foreground session was demoted (e.g. focus moved to a code file mid-turn).
|
E2E Tests 🚀 Why these tags?
More on automatic tags from changed files. |
jmcphers
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #14762
There was a confusing state you could get into where when you navigate off of a positron notebook into a non-editor-type context like a data explorer etc we never triggered the event that caused the assistant chat to think it had left the notebook. This meant that the notebook was still "active" in the chat pane (e.g. the active runtime was the notebook) but when the assistant went to query the notebook the thing we gate on is the notebook being the active editor which if focus is on something like the data explorer then it is not. The result was a confused agent and user because the agent didnt have access to the notebook context it expected. This fixes that by letting the notebook tools search open but not focused editors for the correct notebook.
Agent generated notes 👇
positron.notebooks.getContextresolved the notebook only from the active editor pane, so assistant tools reported "no notebook is open in the editor" whenever focus was anywhere else (a Data Explorer or plot editor opened from the notebook, the chat editor, a split group, another tab) even though a Positron notebook was open. This PR adds a fallback: when no Positron notebook is the active pane,getContextresolves the open notebook attached to the foreground session (what the interpreter picker shows, and what assistant notebook mode is keyed on), then the most recently active open Positron notebook.Two edge behaviors are deliberate:
getContextstill rejects with the actionable "reopen in the Positron Notebook Editor" error rather than falling back to a different open notebook.Release Notes
New Features
Bug Fixes
Validation Steps
@:positron-notebooks @:assistant
Regression tests:
src/vs/workbench/api/test/browser/positron/mainThreadNotebookFeatures.vitest.tscovers the fallback (open-but-inactive notebook, MRU order across multiple notebooks, foreground-session preference, closed foreground notebook, nothing open, and the built-in-editor error).Manual check:
positron.notebook.enabledon) and run a cell so it has a session.Viewa dataframe) so the notebook is no longer the active editor pane.